package sjtu.pirate.report.simple;

import java.io.IOException;
import java.util.List;
import biz.source_code.miniTemplator.MiniTemplator.TemplateSyntaxException;

import sjtu.pirate.analyzer.PirateAnalyzer;
import sjtu.pirate.format.FormResult;
import sjtu.pirate.report.Report;
import sjtu.pirate.report.ReportTemplate;

/**
 * @author wilbur.ma@qq.com
 * @date 2011.05.31
 * Report class generate reports with the following structure:
 * report/
 * 		style/*.css (static files)
 * 		js/*.js (static files)
 * 		img/*.png|*.jpg... (static files)
 * 		index.html (hostIndex)
 * 		detail/
 * 			index.html (formIndex)
 * 			host.../
 * 				formPath+formName.html... (forms)
 */
public class SimpleReport extends Report {
	public SimpleReport(String templatesDir, String targetDir, PirateAnalyzer analyzer) 
			throws TemplateSyntaxException, IOException 
	{
		super(
				templatesDir, 
				targetDir, 
				new String[][]{
					{"simple", "js"},
					{"simple", "img"},
					{"simple", "style"}
				}, 
				analyzer
		);
	}
	
	@Override
	public void initReportTemplates(PirateAnalyzer analyzer) 
			throws TemplateSyntaxException, IOException {
		ReportTemplate hostIndex = new HostIndexTemplate(templatesDir + "/simple/hostIndex.html", targetDir, analyzer);
		templates.add(hostIndex);
		ReportTemplate formIndex = new FormIndexTemplate(templatesDir + "/simple/formIndex.html", targetDir, analyzer);
		templates.add(formIndex);
		for (String host : analyzer.getResults().keySet()) {
			for (List<FormResult> list: analyzer.getResults().get(host).values()) {
				FormsTemplate ft = new FormsTemplate(templatesDir + "/simple/forms.html", targetDir, analyzer, list);
				templates.add(ft);
			}
		}
	}
}
